package com.vm.activity;

import com.wwt.app.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

/**
 * 
 * @ProjectName: [WeiMai]
 * @Author: [kent.wang]
 * @CreateDate: [2015年3月19日 下午2:33:50]
 * @Version: [v1.0]
 * 
 */
public class WelcomeActivity extends Activity {
	private final int SPLASH_DISPLAY_LENGHT = 1000;
	private SharedPreferences preferences;
	private Editor editor;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		final View view = View.inflate(this, R.layout.start, null);
		setContentView(view);
		 preferences = getSharedPreferences("phone", Context.MODE_PRIVATE); 
		// 渐变展示启动屏
		AlphaAnimation aa = new AlphaAnimation(0.3f, 1.0f);
		aa.setDuration(2000);
		view.startAnimation(aa);
		aa.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationEnd(Animation arg0) {
				redirectTo();
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationStart(Animation animation) {
			}

		});

		// //兼容低版本cookie（1.5版本以下，包括1.5.0,1.5.1）
		// AppContext appContext = (AppContext)getApplication();
		// String cookie = appContext.getProperty("cookie");
		// if(StringUtils.isEmpty(cookie)) {
		// String cookie_name = appContext.getProperty("cookie_name");
		// String cookie_value = appContext.getProperty("cookie_value");
		// if(!StringUtils.isEmpty(cookie_name) &&
		// !StringUtils.isEmpty(cookie_value)) {
		// cookie = cookie_name + "=" + cookie_value;
		// appContext.setProperty("cookie", cookie);
		// appContext.removeProperty("cookie_domain","cookie_name","cookie_value","cookie_version","cookie_path");
		// }
		// }
	}

	/**
	 * 跳转到...
	 */
	private void redirectTo() {
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				if (preferences.getBoolean("firststart", true)) {
					editor = preferences.edit();  
				    editor.putBoolean("firststart", false);  
				    editor.commit(); 
				    Intent intent=new Intent();
					intent.setClass(WelcomeActivity.this,AndyViewPagerActivity.class);
					WelcomeActivity.this.startActivity(intent);
					WelcomeActivity.this.finish();
				}else{
					 Intent intent=new Intent();
						intent.setClass(WelcomeActivity.this,MainTabActivity.class);
						WelcomeActivity.this.startActivity(intent);
						WelcomeActivity.this.finish();
					
				}
			}
			
		}, SPLASH_DISPLAY_LENGHT);
	}

}
